package com.example.demo.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.example.demo.pojo.Singer;
import com.example.demo.pojo.User;
import com.example.demo.service.SingerService;



@Controller
@RequestMapping("/singer")
public class SingerAction {
	@Autowired
	private SingerService singerService;
	@RequestMapping("/getSingerList")
	public String getSingerList(Model model) {
		List<Singer> singerList=singerService.getSingerList();
		model.addAttribute("singerList", singerList);
		return "/user/ht_singer";
	}
	@RequestMapping("/searchSingerList")
	public String searchSingerList(String singer_name, String singer_type,Model model) {
		List<Singer> singerList=singerService.searchSingerList(singer_name, singer_type);
		model.addAttribute("singerList", singerList);
		return "/user/ht_singer";
	}
	@RequestMapping("/addSinger")
	public String addSinger(Singer singer,Model model) {
		int i=singerService.addSinger(singer);
		if(i>0) {
			return "forward:/singer/getSingerList";
		}
		else {
			model.addAttribute("result","no");
			model.addAttribute("msg","添加失败");
			return "/user/result";	
		}
	}
	@RequestMapping("/huayu")
	public String getList1(Model model) {
		List<Singer> getlist=singerService.getList1();
		model.addAttribute("huayu", getlist);
		return "singerA";
	}
	@RequestMapping("/yueyu")
	public String getList2(Model model) {
		List<Singer> getlist=singerService.getList2();
		model.addAttribute("yueyu", getlist);
		return "singerB";
	}
	@RequestMapping("/rihan")
	public String getList3(Model model) {
		List<Singer> getlist=singerService.getList3();
		model.addAttribute("rihan", getlist);
		return "singerC";
	}
	@RequestMapping("/oumei")
	public String getList4(Model model) {
		List<Singer> getlist=singerService.getList4();
		model.addAttribute("oumei", getlist);
		return "singerD";
	}

	@RequestMapping("/deleteSinger")
	public String deleteSinger(Singer singer,Model model) {
		boolean f=singerService.deleteSinger(singer);
		if(f) {
			return "forward:/singer/getSingerList";
		}
		else {
			model.addAttribute("result","no");
			model.addAttribute("msg","删除失败");
			return "/user/result";	
		}
	}
	@RequestMapping("/getList")
	public String getList(Model model,int singer_id) {
		Singer singer=singerService.getList(singer_id);
		model.addAttribute("singer",singer);
		return "xiugaigeshou";
	}
	@RequestMapping("/updateSinger")
	public String updateSinger(Model model,Singer singer) {
		boolean f=singerService.updateSinger(singer);
		if(f) {
			return "forward:/singer/getSingerList";
		}
		else {
			model.addAttribute("result","no");
			model.addAttribute("msg","对不起，修改失败！");
			return "/user/result";	
		}
	}
}
